Public Class wxPosition

    Inherits ArrayList

    Private Const mCAPACITY As Int32 = 10

    Private mIndex As Int32
    Private oldLine As Int32

    Public Sub New()
        Me.Capacity = mCAPACITY
    End Sub

    Public Sub StoreCursorPos(ByVal sender As SCI_EDIT)
        Dim newLine As Int32 = sender.LineFromPosition(sender.GetCurrentPos)

        If newLine <> oldLine Then
            Me.AddValue(sender.GetCurrentPos)
            oldLine = newLine
        End If
    End Sub


    Public Function PreviousPos(ByVal sender As SCI_EDIT) As Int32
        If Me.Count = 0 Then Exit Function

        mIndex += 1
        If mIndex >= Me.Count Then mIndex = Me.Count - 1
        If mIndex >= mCAPACITY Then mIndex = mCAPACITY - 1

        sender.GotoPos(Me.Item(mIndex))

    End Function

    Public Function NextPos(ByVal sender As SCI_EDIT) As Int32
        If Me.Count = 0 Then Exit Function

        mIndex -= 1
        If mIndex < 0 Then mIndex = 0

        sender.GotoPos(Me.Item(mIndex))

    End Function

    Public Sub AddValue(ByVal Value As Int32)
        If Me.Count <= mCAPACITY Then
            Me.Insert(0, Value)
            mIndex = 0
        Else
            Me.RemoveAt(mCAPACITY)
            Me.Insert(0, Value)
            mIndex = 0
        End If
    End Sub

    Public Function Position() As Int32
        Return mIndex
    End Function

    Public Sub ClearAll()
        Me.Clear()
        mIndex = 0
        oldLine = 0
    End Sub

End Class
